﻿Ext.define('Oa.ExamTypeGrid', {
    extend: 'Ext.grid.Panel',
    alias: 'Widget.ExamTypeGrid',

    // override
    initComponent: function () {
        this.columns = [
            {
                header: "试卷类别",flex:1,
                dataIndex: 'Title'
            }, {
                header: "开始时间", width: 150,
                dataIndex: 'StartTime'
            }, {
                header: "结束时间", width: 150,
                dataIndex: 'EndTime'
            }, {
                header: "操作", dataIndex: 'Id', width:250, renderer: function (value, a, reader, c, d, ds) {
                    var links = [];
                    links.push('<a href="#" onclick="var url =\'ExamTypeEdit.aspx?id=' + value + '\';window.showModalDialog(url, window, \'dialogWidth=600px;dialogHeight=450px;status=no;help=no;resizable=yes;\');Ext.getCmp(\'QuestionMgr\').getStore().reload();">编辑</a>');
                    links.push('<a href="#" onclick="var url =\'QuestionList.aspx?typeId=' + value + '\';window.open(url);">试题维护</a>');
                    links.push('<a href="#" onclick="var url =\'ExamAuth.aspx?id=' + value + '\';window.showModalDialog(url, window, \'dialogWidth=350px;dialogHeight=560px;status=no;help=no;resizable=yes;\');">答题人</a>');
                    links.push('<a href="#" onclick="var url =\'ExamStat.aspx?typeId=' + value + '\';window.open(url);">结果统计</a>');
                    return links.join("&nbsp;");
                }
            }
        ];
        // Set up a model to use in our Store
        Ext.define('ExamTypeModel', {
            extend: 'Ext.data.Model',
            fields: [{
                name: 'Id'
            }, {
                name: 'Title'
            }, {
                name: 'Testers'
            }, {
                name: 'StartTime'
            }, {
                name: 'EndTime'
            }, {
                name: 'Greetings'
            }, {
                name: 'Conclusion'
            }]
        });

        var ds = Ext.create('Ext.data.Store', {
            model: 'ExamTypeModel',
            pageSize: 20, // items per page
            proxy: {
                type: 'ajax',
                url: '/Exam.mvc/Find',
                reader: {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'totalCount'//分页使用
                }
            },
            autoLoad: false
        });
        ds.load({ params: { start: 0, limit: 20 } });
        this.store = ds;

        this.dockedItems = [{
            xtype: 'toolbar',
            dock: 'top',
            items: [{
                text: "添加",
                tooltip: "添加新的信息",
                iconCls: "addicon",
                handler: function () {
                    var url = 'ExamTypeEdit.aspx';
                    var retVal = window.showModalDialog(url, window, 'dialogWidth=600px;dialogHeight=450px;status=no;help=no;');
                    if (retVal != undefined && retVal == "Succeed") {
                        ds.reload();
                    }
                }
            }]
        }, {
            xtype: 'pagingtoolbar',
            id: 'pagingExamType',
            store: ds,
            dock: 'bottom',
            displayInfo: true
        }];

        // finally call the superclasses implementation
        Oa.ExamTypeGrid.superclass.initComponent.call(this);
    }
});